import Vue from 'vue'


Vue.directive('img-reload', {
  bind: function (el, binding, vnode) {
    //debugger
    let {expression} = binding
    //let src = el.src
    let loadTime = 1500
    let loadNum = 0
    let loadMaxNum = +expression || 2
    let loaded = false
    el.onload = function () {
      loaded = true
      el.src = el.src
      clearTimeout(setTime)
    }
    el.onerror = function () {
      if(loadNum > 1){
        return
      }
      clearTimeout(setTime)
      el.src = el.src
      loadNum++
    }

    let setTime = setTimeout(()=>{
      if(loaded){
        return
      }
      loadNum++
      el.src = el.src
    }, loadTime)

  }
})
